﻿using System;
using System.Collections.Generic;
using System.Text;
using Hermes.Framework.FileSystem.SharePoint;
using NUnit.Framework;

namespace Hermes.Framework.Test.FileSystem
{
    [TestFixture]
    public class SharePointFileSystemTest
    {
        protected string host = "http://ds-srv-01:18712/";

        protected string sourceFileName = @"c:\hello.txt";

        protected string targetFileName = @"/shared%20documents/hello.txt";

        protected string sourceDirectoryName = @"/shared%20documents/hello/";

        protected string targetDirectoryName = @"/shared%20documents/world/";

        protected SharePointFileSystem fileSystem = null;

        public SharePointFileSystemTest()
        {
            this.fileSystem = new SharePointFileSystem(this.host);
        }

        [SetUp]
        public void SetUp()
        {

        }

        [TearDown]
        public void TearDown()
        {

        }

        [Test]
        public void CreateFileTest()
        {

        }

        [Test]
        public void CopyFileTest()
        {
            this.fileSystem.Copy(this.sourceFileName, this.targetFileName);

            Assert.IsTrue(this.fileSystem.Exists(this.targetFileName));

            this.fileSystem.DeleteFile(this.targetFileName);
        }

        [Test]
        public void DeleteFileTest()
        {
            if (!this.fileSystem.Exists(this.targetFileName))
            {
                this.CreateFileTest();
            }
            this.fileSystem.DeleteFile(this.targetFileName);

            Assert.IsFalse(this.fileSystem.Exists(this.targetFileName));
        }

        [Test]
        public void RenameFileTest()
        {
            if (!this.fileSystem.Exists(this.targetFileName))
            {
                this.fileSystem.Copy(this.sourceFileName, this.targetFileName);
            }
            if (this.fileSystem.Exists("/shared%20documents/world.txt"))
            {
                this.fileSystem.DeleteFile("/shared%20documents/world.txt");
            }
            this.fileSystem.Rename(this.targetFileName, "/shared%20documents/world.txt");

            Assert.IsFalse(this.fileSystem.Exists(this.targetFileName));
            Assert.IsTrue(this.fileSystem.Exists("/shared%20documents/world.txt"));

            this.fileSystem.DeleteFile("/shared%20documents/world.txt");
        }

        [Test]
        public void CreateDirectoryTest()
        {
            this.fileSystem.CreateDirectory(this.targetDirectoryName);

            Assert.IsTrue(this.fileSystem.IsDirectory(this.targetDirectoryName));

            this.fileSystem.DeleteDirectory(this.targetDirectoryName);
        }

        [Test]
        public void DeleteDirectory()
        {
            if (this.fileSystem.IsDirectory(this.targetDirectoryName))
            {
                this.fileSystem.DeleteDirectory(this.targetDirectoryName);
            }
            this.CreateDirectoryTest();

            this.fileSystem.DeleteDirectory(this.targetDirectoryName);

            Assert.IsFalse(this.fileSystem.IsDirectory(this.targetDirectoryName));
        }

        [Test]
        public void RenameDirectoryTest()
        {
            if (!this.fileSystem.IsDirectory(this.targetDirectoryName))
            {
                this.fileSystem.CreateDirectory(this.targetDirectoryName);
            }
            this.fileSystem.RenameDirectory(
                this.targetDirectoryName, "/shared%20documents/presentations");

            Assert.IsFalse(this.fileSystem.IsDirectory(this.targetDirectoryName));
            Assert.IsTrue(this.fileSystem.IsDirectory("/shared%20documents/presentations"));

            this.fileSystem.DeleteDirectory("/shared%20documents/presentations");
        }
    }
}
